<template>
  <div class="" >
    <div class="ui dividing header">操作</div>
    <editCom v-if="modalShow&&new_detail_id" :otherEdit='true' otherEdit_mid='75' @dosth="dosth"></editCom>
    <div class="ui dividing header">
      <button class="ui button" @click.stop.prevent="seeLog">查看跟进日历</button>
    </div>

    <div class="ui dividing header">
      <button class="ui button" @click.stop.prevent="toRefund">退单</button>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';
import editCom from 'components/edit/editCom'

export default {
  data() {
    return {
      taillog:null,
      log_fields:null,
      log_titles:null,
      new_detail_id:false,
      lastOne:null
    }
  },
  methods: {
    toRefund(){
      let url = tool.getApi(this, 'Op','refund');
      let param = {
        id:this.detail_id
      };
      util.http.SR(this, url, param, '操作成功!', (rs) => {
      });
    },
    seeLog(){
      let fields = this.log_fields;
      let titles = this.log_titles;
      let vals=this.taillog;
      let info = {
        _id:this.detail_id,
//        refresh:true,
        refresh:false,
        rs:{
          many_line:true,
//          title:'跟进日志(最近8条)',
          title:'跟进日志',
          vals,titles,fields
        }
      };
      logic.detail.show_click_see(this, info);

    },
    getTaillog(){
      let url = tool.getApi(this, 'Listget','getTailInfo');
      let param = {
        detail_id:this.detail_id
      };
      util.getDataCom(this, url, param, (rs) => {
        this.taillog = rs.logs;
        this.log_fields=rs.fields;
        this.log_titles=rs.titles;

        this.lastOne = rs.last;

        this.new_detail_id=true;

        util.store.commit(this,'set_otherEdit_op', 'update');
        util.store.commit(this,'setOtherEditVo', this.lastOne||{});
      });
    },
    dosth(vo){
      let url = tool.getApi(this, 'Taillog','insert');
      let param = {
        detail_id:this.detail_id,
        status:vo.status,
        remark:vo.remark
      };
      util.http.SR(this, url, param, '跟进操作成功', (rs) => {
        logic.list.refreshListData(this);
        this.getTaillog();
      });
//      },{showMypop:true});
    }
  },
  created(){
    this.getTaillog();
  },
  watch: {
    detail_id:function (val,old) {
      if(val) {
        this.new_detail_id=false;
        this.getTaillog();
      }
    }
  },
  computed: {
  },
  components: {
    editCom
  },
  props: ['ctl','items_all','detail_id','modalShow']
};
</script>

<style rel="stylesheet/less"  lang="less">
</style>
